import { AutoFight } from "./AutoFight";
import { GTextFormat } from "../../../common/GTextFormat";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
import { ItemTypeManager } from "./ItemTypeManager";
type int = number;
//class OtherThingsSetPanel
    
    export  class OtherThingsSetPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            return;
        }

        public set itemOtherThings(arg1: Boolean)
        {
            this._itemOtherThings.enabled = arg1;
            this._itemOtherThings.selected = arg1;
            if (this._itemOtherThings.selected) 
            {
                AutoFight.localAutoFight.pickOtherThingsIdx = [];
                this._changeShapeCb.selected = true;
                this._wineFireWoodCb.selected = true;
                this._petSundriesCb.selected = true;
                this._propSoapCb.selected = true;
                this._skillBookCb.selected = true;
            }
            else 
            {
                AutoFight.localAutoFight.pickOtherThingsIdx = [4, 5, 6, 7, 8, 9, 10];
                this._changeShapeCb.selected = false;
                this._wineFireWoodCb.selected = false;
                this._petSundriesCb.selected = false;
                this._propSoapCb.selected = false;
                this._skillBookCb.selected = false;
            }
            return;
        }

        /* internal  */init(): void
        {
            var loc1=new GTextFormat("", 12, 65280);
            this._itemOtherThings = ObjCreate.createCheckBox(Language.getString(34053), 0, 0, 80, 20, this, "GCheckBox");
            this._itemOtherThings.setStyle("textFormat", GlobalStyle.textFormat2);
            this._itemOtherThings.addEventListener(flash.events.Event.CHANGE, this.onOtherThingsChangeHandler);
            this._changeShapeCb = ObjCreate.createCheckBox(Language.getString(34054), 0, 25, 80, 20, this, "CheckBoxStyle");
            this._changeShapeCb.setStyle("textFormat", loc1);
            this._changeShapeCb.addEventListener(flash.events.Event.CHANGE, this.onChangeShapeChangeHandler);
            this._propSoapCb = ObjCreate.createCheckBox(Language.getString(34056), 160, 25, 80, 20, this, "CheckBoxStyle");
            this._propSoapCb.setStyle("textFormat", loc1);
            this._propSoapCb.addEventListener(flash.events.Event.CHANGE, this.onPropSoapChangeHandler);
            this._skillBookCb = ObjCreate.createCheckBox(Language.getString(34057), 0, 50, 80, 20, this, "CheckBoxStyle");
            this._skillBookCb.setStyle("textFormat", loc1);
            this._skillBookCb.addEventListener(flash.events.Event.CHANGE, this.onSkillBookChangeHandler);
            this._petSundriesCb = ObjCreate.createCheckBox(Language.getString(34058), 80, 25, 80, 20, this, "CheckBoxStyle");
            this._petSundriesCb.setStyle("textFormat", loc1);
            this._petSundriesCb.addEventListener(flash.events.Event.CHANGE, this.onPetSundriesChangeHandler);
            this._wineFireWoodCb = ObjCreate.createCheckBox(Language.getString(34059), 80, 50, 80, 20, this, "CheckBoxStyle");
            this._wineFireWoodCb.setStyle("textFormat", loc1);
            this._wineFireWoodCb.addEventListener(flash.events.Event.CHANGE, this.onWineFireWoodChangeHandler);
            return;
        }

        /* internal  */onOtherThingsChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this.updatePickOtherThings();
            return;
        }

        /* internal  */updatePickOtherThings(): void
        {
            if (this._itemOtherThings.selected) 
            {
                AutoFight.localAutoFight.pickOtherThingsIdx = [];
                this._changeShapeCb.selected = true;
                this._wineFireWoodCb.selected = true;
                this._petSundriesCb.selected = true;
                this._propSoapCb.selected = true;
                this._skillBookCb.selected = true;
            }
            else 
            {
                AutoFight.localAutoFight.pickOtherThingsIdx = [4, 5, 6, 7, 8, 9, 10];
                this._changeShapeCb.selected = false;
                this._wineFireWoodCb.selected = false;
                this._petSundriesCb.selected = false;
                this._propSoapCb.selected = false;
                this._skillBookCb.selected = false;
            }
            AutoFight.localAutoFight.alter = true;
            return;
        }

        /* internal  */onChangeShapeChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this.operPickOtherThingsArr(4, this._changeShapeCb);
            return;
        }

        /* internal  */onCoinSundriesChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            return;
        }

        /* internal  */onPropSoapChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this.operPickOtherThingsArr(5, this._propSoapCb);
            return;
        }

        /* internal  */onSkillBookChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this.operPickOtherThingsArr(6, this._skillBookCb);
            return;
        }

        /* internal  */onPetSundriesChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this.operPickOtherThingsArr(10, this._petSundriesCb);
            return;
        }

        /* internal  */onWineFireWoodChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this.operPickOtherThingsArr(7, this._wineFireWoodCb);
            this.operPickOtherThingsArr(8, this._wineFireWoodCb);
            return;
        }

        /* internal  */operPickOtherThingsArr(arg1: int, arg2: GCheckBox): void
        {
            if (!this._itemOtherThings.selected) 
            {
                return;
            }
            var loc1=AutoFight.localAutoFight.pickOtherThingsIdx;
            var loc2=loc1.indexOf(arg1);
            if (arg2.selected && !(loc2 == -1)) 
            {
                AutoFight.localAutoFight.pickOtherThingsIdx.splice(loc2, 1);
                AutoFight.localAutoFight.alter = true;
            }
            else if (!arg2.selected && loc2 == -1) 
            {
                AutoFight.localAutoFight.pickOtherThingsIdx.push(arg1);
                AutoFight.localAutoFight.alter = true;
            }
            return;
        }

        public resetOtherThingsPanel(): void
        {
            var loc3=null;
            this._changeShapeCb.selected = true;
            this._wineFireWoodCb.selected = true;
            this._petSundriesCb.selected = true;
            this._propSoapCb.selected = true;
            this._skillBookCb.selected = true;
            var loc1=AutoFight.currentAutoFight.pickOtherThings;
            var loc2=AutoFight.currentAutoFight.pickOtherThingsIdx;
            var loc4=0;
            var loc5=loc1;
            for(loc3 of loc5) 
            {
                if (loc3 == ItemTypeManager.instance.changeShape) 
                {
                    this._changeShapeCb.selected = false;
                    continue;
                }
                if (loc3 == ItemTypeManager.instance.coinSundries) 
                {
                    continue;
                }
                if (loc3 == ItemTypeManager.instance.fireWood || loc3 == ItemTypeManager.instance.wine) 
                {
                    this._wineFireWoodCb.selected = false;
                    continue;
                }
                if (loc3 == ItemTypeManager.instance.petSundries) 
                {
                    this._petSundriesCb.selected = false;
                    continue;
                }
                if (loc3 == ItemTypeManager.instance.propSoap) 
                {
                    this._propSoapCb.selected = false;
                    continue;
                }
                if (loc3 != ItemTypeManager.instance.skillBook) 
                {
                    continue;
                }
                this._skillBookCb.selected = false;
            }
            if (loc1.length < 7) 
            {
                this._itemOtherThings.selected = true;
            }
            else 
            {
                this._itemOtherThings.selected = false;
            }
            return;
        }

        /* internal */ /* var */_itemOtherThings: GCheckBox;

        /* internal */ /* var */_changeShapeCb: GCheckBox;

        /* internal */ /* var */_propSoapCb: GCheckBox;

        /* internal */ /* var */_skillBookCb: GCheckBox;

        /* internal */ /* var */_petSundriesCb: GCheckBox;

        /* internal */ /* var */_wineFireWoodCb: GCheckBox;
    }
